package com.manor.main.adapter;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.manor.main.R;
import com.manor.main.bean.OnlineUserBean;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class OnLineUserAdapter extends BaseQuickAdapter<OnlineUserBean, BaseViewHolder> {
    Animation rotateAnim = null;


    public OnLineUserAdapter(int layoutResId, @Nullable List<OnlineUserBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, OnlineUserBean item) {
        ImageView imgBg = helper.getView(R.id.iv_img_bg);
        FrameLayout flName = helper.getView(R.id.fl_name);
        TextView tvName = helper.getView(R.id.tv_name);
        helper.setText(R.id.tv_name, item.getName());


        rotateAnim = AnimationUtils.loadAnimation(getContext(), R.anim.view_anim_rotate);
        rotateAnim.setRepeatCount(ValueAnimator.INFINITE);
        imgBg.startAnimation(rotateAnim);

        int width = helper.getView(R.id.tv_name).getWidth();

        helper.getView(R.id.iv_img_bg).getLayoutParams().width=width;
        helper.getView(R.id.iv_img_bg).getLayoutParams().height=width;

      /*  int height = tvName.getHeight();
        imgBg.setMaxHeight(height);
        ViewGroup.LayoutParams lp;
        lp = imgBg.getLayoutParams();
        lp.width = height;
        lp.height = height;*/


        ObjectAnimator animation = ObjectAnimator.ofFloat(flName, "translationX", 100f);
        animation.setDuration(2000);
        animation.start();


    }
}
